package eleven;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.util.Date;

public class UDPObjClient {
    public static void main(String[] args) throws Exception {
        System.out.println("UDPClient启动中...");
        DatagramSocket client = new DatagramSocket(8888);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(baos));
        oos.writeUTF("编码辛酸泪");
        oos.writeInt(18);
        oos.writeBoolean(false);
        oos.writeChar('a');
        oos.writeObject("谁解其中味");
        oos.writeObject(new Date());
        Employee emp = new Employee("马云", 400);
        oos.writeObject(emp);
        oos.flush();
        byte[] datas = baos.toByteArray();
        System.out.println(datas.length);
        DatagramPacket packet = new DatagramPacket(datas, 0 ,datas.length,
                new InetSocketAddress("localhost", 9999));
        client.send(packet);
    }
}
